#
# Run experiments for diploma thesis (new, DPM kernels).
#

use strict;
use warnings;

my $home = 'C:\Users\ungerma\Desktop\DA\dual-process-model\dpm';
my $run = "$home\\dist\\Debug\\MinGW-Windows\\dpm.exe ";
my $additional = '-# 3000 -m 512';

sub printRun {
  my $cmd = shift;
  print "$cmd\n";
  return system($cmd);
}

printRun($run . 'features') == 0 or die('Could not run cmd');
for my $mode (1, ) {
  for my $gf (  2, 1, 4, 0, 5, ) { #
    for my $lhs (1, ){ # similarity, ie. not distance # 2, 5, 6, 8, 10, 11, 12, 14,
	  for my $rhs ( 0, 3, 4, 7,9, 13, 15, 16, 17, 18, 19,) { # distance, ie. x-y or x/y # 
	  
		# These cases do not terminate.
		next if $rhs == 7;
		next if $rhs == 9;
	    next if $lhs == 10;
		next if $lhs == 12;
	  
	    next if printRun($run . "train \"-t 4 -g $gf -s $lhs -d $rhs -r $mode  $additional\"");
		next if printRun($run . 'classify');
		opendir D, "$home\\gen" or die "Could not open dir: $!\n";
		my @files = grep(/pr\d+/i, readdir D);
		closedir D;
		if(scalar @files == 1) {
			my $file = $files[0];
			$file =~ /(\d+)/;
			my $score = $1;
			next if printRun("move $home\\gen\\$file $home\\gen\\pr-${score}-${mode}-${gf}-${lhs}-${rhs}.txt");
		}
		else {
			die("Did not find exactly one proper result file.");
		}
	  }
	}
  }
}
